package cn.pegasus.teamwork.pegasus.service.impl;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.pegasus.teamwork.pegasus.entity.BussNewsInfo;
import cn.pegasus.teamwork.pegasus.mapper.BussNewsInfoMapper;
import cn.pegasus.teamwork.pegasus.service.BussNewsInfoService;
import cn.iyizhan.teamwork.base.service.impl.BaseServiceImpl;
import cn.iyizhan.teamwork.base.util.PageObject;

/**
 * @author ryan.bian
 * @version 
 */
@Service("bussNewsInfoService")
public class BussNewsInfoServiceImpl extends BaseServiceImpl<BussNewsInfo, BussNewsInfoMapper> implements BussNewsInfoService {
	// 注入当前dao对象
    @Autowired
    private BussNewsInfoMapper bussNewsInfoMapper;

    public BussNewsInfoServiceImpl() {
        setMapperClass(BussNewsInfoMapper.class, BussNewsInfo.class);
    }

	@Override
	public PageObject<BussNewsInfo> PageList(Map<String, Object> map) {
		map.put("sortName", "create_time");
        map.put("sortOrder", "desc");
        map.put("newsStatus", 1);
		return super.Pagequery(map);
	}

	@Override
	public void addNews(Long userId,BussNewsInfo info) {
		info.setCreateTime(new Date());
		info.setCreateUserBy(userId);
		info.setUpdateTime(new Date());
		info.setUpdateUserBy(userId);
		info.setNewsStatus(1);
		bussNewsInfoMapper.insertByEntity(info);
	}

	@Override
	public void updateNews(Long userId,BussNewsInfo info) {
		info.setUpdateTime(new Date());
		info.setUpdateUserBy(userId);
		bussNewsInfoMapper.updateByEntity(info);
	}

	@Override
	public void deleteNews(Long userId, Integer id) {
		BussNewsInfo info = new BussNewsInfo();
		info.setId(id);
		info.setNewsStatus(2);
		info.setUpdateTime(new Date());
		info.setUpdateUserBy(userId);
		bussNewsInfoMapper.updateByEntity(info);
	}

	@Override
	public BussNewsInfo findNewsInfo(Integer id) {
		BussNewsInfo info = new BussNewsInfo();
		info.setId(id);
		return bussNewsInfoMapper.selectSingle(info);
	}
    
 
}
